import { getCategories,getCategoriesAttributes,putCategories,deleteCategories,postCategories,postAddCategories} from '@/api/categorie'
const state={
     //发送请求的参数
    pagination:{
        type:[1,2,3],
        //当前页码	
        pagenum:1,
        //每页显示条数
        pagesize:2,
    },
    //响应后取到的pagination数据
    paginationData:{
        //总页数
        total:null,
    },
    //categories的页面数据
    categories_data:[],
    //添加分类
    goods_cat:[],

};
const getters={};
const mutations={
     //修改参数pagenum
    CHANGE_PAGENUM(state,playLoad){
        state.pagination.pagenum=playLoad;
    },
   //修改参数pagesize
    CHANGE_PAGESIZE(state,playLoad){
        state.pagination.pagesize=playLoad;
    },
    //修改获取到的pagination的total数据
    CHANGE_TOTAL(state,playLoad){
        state.paginationData.total=playLoad;
    },
    //categories的页面数据
    CHANGE_CATEGORIES_DATA(state,playLoad){
        state.categories_data=playLoad;
    },
    //添加分类
    CHANGE_GOODS_CAT(state,playLoad){
        state.goods_cat=playLoad
    }

};
const actions={
     //异步商品分类数据列表
    Acs_getCategories(){
        return new Promise((resolve,reject)=>{
            getCategories()
            .then(res=>{
                resolve(res);
            })
            .catch(err=>{
                reject(err)
            })
        })
    },
    //异步获取参数列表(动态/静态)
    Acs_getCategoriesAttributes(content,playload){
        return new Promise((resolve,reject)=>{
            getCategoriesAttributes(playload)
            .then(res=>{
                resolve(res);
            })
            .catch(err=>{
                reject(err)
            })
        })
    },
    //编辑提交参数
    Acs_putCategories(content,playload){
        return new Promise((resolve,reject)=>{
            putCategories(playload)
            .then(res=>{
                resolve(res);
            })
            .catch(err=>{
                reject(err)
            })
        })
    },
    // 删除参数
    Acs_deleteCategories(content,playload){
        return new Promise((resolve,reject)=>{
            deleteCategories(playload)
            .then(res=>{
                resolve(res);
            })
            .catch(err=>{
                reject(err)
            })
        })
    },
    //添加动态参数或者静态属性
    Acs_postCategories(content,playload){
        return new Promise((resolve,reject)=>{
            postCategories(playload)
            .then(res=>{
                resolve(res);
            })
            .catch(err=>{
                reject(err)
            })
        })
    },
    //添加分类
    Acs_postAddCategories(content,playload){
        return new Promise((resolve,reject)=>{
            postAddCategories(playload)
            .then(res=>{
                resolve(res);
            })
            .catch(err=>{
                reject(err)
            })
        })
    }


};

export default {
    namespaced:true,
    state,
    getters,
    mutations,
    actions
}